package com.smartwebx.ha.dal.realtime.sqlprovider;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.FROM;
import static org.apache.ibatis.jdbc.SqlBuilder.INNER_JOIN;
import static org.apache.ibatis.jdbc.SqlBuilder.SELECT;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import java.util.Map;

import com.smartwebx.ha.dal.config.OracleConfigInfo;

public class StDayevRProvider {
	private static final String MAIN_NAME = OracleConfigInfo.REALTIME_NAME
			+ ".ST_DAYEV_R";
	private static final String STATION_NAME = OracleConfigInfo.REALTIME_NAME
			+ ".ST_STBPRP_B";

	public String getAllStatDyeSQL(Map<String, Object> parameters) {
		BEGIN();
		SELECT("B.LGTD,B.LTTD,A.STCD,B.STNM,B.ADDVCD isProvince,'BB' STTP");
		SELECT("B.FRGRD,A.TM  date1,A.DYE VALUE");
		FROM(MAIN_NAME + " A");
		INNER_JOIN(STATION_NAME + " B on A.STCD=B.STCD");
		INNER_JOIN(MAIN_NAME + " C on A.STCD=C.STCD");
		WHERE("C.TM < A.TM");
		WHERE("C.TM > #{startDate}");
		WHERE("C.TM <= #{endDate}");
		WHERE("B.STTP IN('DD','PP','RR','SS','ZQ','ZZ') AND B.LGTD IS NOT NULL AND B.LTTD IS NOT NULL AND ADDVCD IS NOT NULL");
		WHERE("A.TM > #{startDate}");
		WHERE("A.TM <= #{endDate}");
		return SQL();
	}
}
